package pox.mantianx.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import pox.mantianx.pojo.User;
import pox.mantianx.utils.JsonUtils;

import java.util.Date;

/**
 * @author starrysky
 * @title: MyController
 * @projectName springMvc_Parent
 * @description: TODO
 * @date 2021/2/514:11
 */
@Controller
public class MyController {

    @PostMapping("/restUser")
    public String restUser(@RequestParam("name") String name, ModelMap map) {
        System.out.println(name);
        map.addAttribute("msg", name);
        return "upDate";
    }

    @GetMapping("/date")
    @ResponseBody
    public String date() {
        return JsonUtils.toDateFormat(new Date(), "yyyy-MM-dd HH:mm:ss");
    }

    @GetMapping("getUser")
    @ResponseBody
    public String getUser() {
        return JsonUtils.toAllAsString(new User(1L, "虚饰", 16, "12e123@qq.com"));
    }


}
